package com.gegao.StatePattern;

/**
 * Created by zhangzhanzhong on 2016/01/11.
 */
public class Account {
    private String state;
    private int balance;

    /**
     * 存款操作
     */
    public void deposit() {
        //存款
        stateCheck();
    }

    /**
     * 取款操作
     */
    public void withdraw() {
        if (state.equalsIgnoreCase("NormalState") || state.equalsIgnoreCase("OverdraftState ")) {
            //取款
            stateCheck();
        } else {
            //取款受限
        }
    }

    /**
     * 计算利息操作
     */
    public void computeInterest() {
        if (state.equalsIgnoreCase("OverdraftState") || state.equalsIgnoreCase("RestrictedState ")) {
            //计算利息
        }
    }

    public void stateCheck() {
        if (balance >= 0) {
            state = "NomalState";
        } else if (balance > -2000 && balance < 0) {
            state = "OverdraftState";
        } else if (balance == -2000) {
            state = "RestrictedState";
        } else if (balance < -2000) {
            //操作受限
        }

    }
}
